package com.example.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Data
@Component
@ConfigurationProperties(prefix = "alipay") //读取到application.yml
public class AliPayConfig {
    private String appId;
    private String appPrivateKey;
    private String alipayPublicKey;
    //异步通知回调地址（可选）
    private String notifyUrl;
    //支付成功后的回调地址
    private String returnUrl;

    private String gatewayUrl;
    private String format;
    private String charset;
    private String signType;

    @PostConstruct
    public void init(){
        System.out.println("=======支付宝配置初始化=======");
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi.alipaydev.com";
        config.signType = "RSA2";
        config.appId = this.appId;
        config.merchantPrivateKey = this.appPrivateKey;
        config.alipayPublicKey = this.alipayPublicKey;
        config.notifyUrl = this.notifyUrl;
        Factory.setOptions(config);
        System.out.println("=======支付宝SDK初始化成功=======");
    }
}
